package cn.lecosa.spark.redis

import org.apache.commons.pool2.impl.GenericObjectPoolConfig
import redis.clients.jedis.JedisPool
import org.json.JSONObject

 object RedisClient extends Serializable {
 
  val redisHost = "park01"
  val redisPort = 6379
  val redisTimeout = 30000
  lazy val pool = new JedisPool(new GenericObjectPoolConfig(), redisHost, redisPort, redisTimeout)
 
  lazy val hook = new Thread {
    override def run = {
      println("Execute hook thread: " + this)
      pool.destroy()
    }
  }
  sys.addShutdownHook(hook.run)
 
 
  def main(args: Array[String]): Unit = {
    val dbIndex = 0
 
    val jedis = RedisClient.pool.getResource
    jedis.select(dbIndex)
//    jedis.set("test", "1")
//    println(jedis.get("a"))
    
//    val jsonObject = JSONObject.fromObject(jedis.get( "500000_116"));
/*          var jsonObject = new JSONObject(jedis.get( "500000_116"));
    
      
    	val address = jsonObject.get("attrs");
			// 设备的经度
			val longitude = jsonObject.get("lng");
			// 设备的纬度
			val latitude =   jsonObject.get("lat");
			println(address +"  "+longitude+"  " + latitude);
			*/
			

//    RedisClient.pool.returnResource(jedis)
 
  }
 
 
}